using UnityEngine;
using FrameOperateSync;

public class SyncFrameConfig : ScriptableObject
{
    [Header("单机模式")]
    public bool siglePlayerMode = false;
    [Header("逻辑帧间隔")]
    public int frameDuration;
    [Header("buff")]
    public int buffCount;
    [Header("打印延迟日志")]
    public bool logLagInfoFlag;
    [Header("打印核心日志")]
    public bool logCoreInfoFlag;
    [Header("开启延迟模拟")]
    public bool networkLagSimulate;
    [Header("固定延迟时长")]
    public int networkLagTime;
    [Header("波动延迟时长")]
    public int networkWaveMax;

#if UNITY_EDITOR
    [UnityEditor.MenuItem("Assets/FFFF")]
    static void create()
    {
        var config = ScriptableObject.CreateInstance<SyncFrameConfig>();
        UnityEditor.AssetDatabase.CreateAsset(config, "Assets/Plugins/OpSync/Resources/Frame.asset");
    }
#endif

    public static SyncFrameConfig GetConfig()
    {
        var config = Resources.Load<SyncFrameConfig>("Frame");
        return config;
    }

    [RuntimeInitializeOnLoadMethod]
    static void OnFrameSetting()
    {
        var config = SyncFrameConfig.GetConfig();

        Debug.Log("singlePlayerMode = "+config.siglePlayerMode);
        
        HelperUtility.SetSetting("siglePlayerMode", config.siglePlayerMode);
        HelperUtility.SetSetting("frameDuration", config.frameDuration);
        HelperUtility.SetSetting("buffCount", config.buffCount);
        HelperUtility.SetSetting("enableDelayInfoFlag", config.logLagInfoFlag);
        HelperUtility.SetSetting("coreRuntimeInfoFlag", config.logCoreInfoFlag);
        HelperUtility.SetSetting("networkLagSimulate", config.networkLagSimulate);
        HelperUtility.SetSetting("networkLagTime", config.networkLagTime);
        HelperUtility.SetSetting("networkWaveMax", config.networkWaveMax);
    }
    
    public static void SetFrameSetting(SyncFrameConfig config)
    {
        HelperUtility.SetSetting("siglePlayerMode", config.siglePlayerMode);
        HelperUtility.SetSetting("frameDuration", config.frameDuration);
        HelperUtility.SetSetting("buffCount", config.buffCount);
        HelperUtility.SetSetting("enableDelayInfoFlag", config.logLagInfoFlag);
        HelperUtility.SetSetting("coreRuntimeInfoFlag", config.logCoreInfoFlag);
        HelperUtility.SetSetting("networkLagSimulate", config.networkLagSimulate);
        HelperUtility.SetSetting("networkLagTime", config.networkLagTime);
        HelperUtility.SetSetting("networkWaveMax", config.networkWaveMax);
    }
}
